home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************/
- /* */
- /* TurboCAD for Windows */
- /* Copyright (c) 1993 - 2001 */
- /* International Microcomputer Software, Inc. */
- /* (IMSI) */
- /* All rights reserved. */
- /* */
- /******************************************************************/
-
- // MDDialog.cpp : implementation file
- //
-
- #include "stdafx.h"
- #include "MakeDwg.h"
- #include "MDDialog.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CAboutDlg dialog used for App About
-
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
-
- // Dialog Data
- //{{AFX_DATA(CAboutDlg)
- enum { IDD = IDD_ABOUTBOX };
- //}}AFX_DATA
-
- // ClassWizard generated virtual function overrides
- //{{AFX_VIRTUAL(CAboutDlg)
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
- //}}AFX_VIRTUAL
-
- // Implementation
- protected:
- //{{AFX_MSG(CAboutDlg)
- //}}AFX_MSG
- DECLARE_MESSAGE_MAP()
- };
-
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- //{{AFX_DATA_INIT(CAboutDlg)
- //}}AFX_DATA_INIT
- }
-
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAboutDlg)
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- //{{AFX_MSG_MAP(CAboutDlg)
- // No message handlers
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CMakeDwgDlg dialog
-
- CMakeDwgDlg::CMakeDwgDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CMakeDwgDlg::IDD, pParent),
- m_pIApplication(NULL) // TurboCAD SDK: initialize
- {
- //{{AFX_DATA_INIT(CMakeDwgDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
-
- // TurboCAD SDK: make sure we release the application
- CMakeDwgDlg::~CMakeDwgDlg()
- {
- m_view.SetView(NULL);
-
- // Finished with application, decrement the reference count
- if (m_pIApplication != NULL)
- m_pIApplication->Release();
- }
-
- void CMakeDwgDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMakeDwgDlg)
- // NOTE: the ClassWizard will add DDX and DDV calls here
- //}}AFX_DATA_MAP
- }
-
- BEGIN_MESSAGE_MAP(CMakeDwgDlg, CDialog)
- //{{AFX_MSG_MAP(CMakeDwgDlg)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- ON_BN_CLICKED(IDC_ADDCIRCLE, OnAddCircle)
- ON_BN_CLICKED(IDC_ADDLINE, OnAddLine)
- ON_BN_CLICKED(IDC_ADDSPLINE, OnAddSpline)
- ON_BN_CLICKED(IDC_NEWDRAWING, OnNewDrawing)
- ON_BN_CLICKED(IDC_INPROC_SERVER, OnInprocServer)
- ON_BN_CLICKED(IDC_LOCAL_SERVER, OnLocalServer)
- ON_BN_CLICKED(IDC_OPENDRAWING, OnOpenDrawing)
- ON_BN_CLICKED(IDC_SAVEDRAWING, OnSaveDrawing)
- ON_BN_CLICKED(IDC_GETACTIVE, OnGetActive)
- ON_LBN_SELCHANGE(IDC_LISTDRAWINGS, OnSelchangeDrawings)
- ON_BN_CLICKED(IDC_ADDBEZIER, OnAddBezier)
- ON_WM_DESTROY()
- ON_BN_CLICKED(IDC_CURVESMOOTH, OnCurveSmooth)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CMakeDwgDlg message handlers
-
- // TurboCAD SDK: TurboCAD Class Identifier and Interface Identifier
- const CLSID CLSID_Application = {0x6A481001,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
- const CLSID CLSID_XApplication = {0x6A481801,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
- const IID IID_IApplication = {0x6A481101,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
-
-
- BOOL CMakeDwgDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TurboCAD SDK: associate the view with static on dialog box
- m_view.SubclassDlgItem(IDC_PREVIEWRECT, this);
-
- // Add "About..." menu item to system menu.
-
- // IDM_ABOUTBOX must be in the system command range.
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
-
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
-
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- SetIcon(m_hIcon, TRUE); // Set big icon
- SetIcon(m_hIcon, FALSE); // Set small icon
-
- // TODO: Add extra initialization here
-
- return TRUE; // return TRUE unless you set the focus to a control
- }
-
- void CMakeDwgDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
-
- // If you add a minimize button to your dialog, you will need the code below
- // to draw the icon. For MFC applications using the document/view model,
- // this is automatically done for you by the framework.
-
- void CMakeDwgDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // device context for painting
-
- SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
-
- // Center icon in client rectangle
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
-
- // Draw the icon
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
-
- // The system calls this to obtain the cursor to display while the user drags
- // the minimized window.
- HCURSOR CMakeDwgDlg::OnQueryDragIcon()
- {
- return (HCURSOR) m_hIcon;
- }
-
- const IID IID_Properties = {0x6A48110F,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
-
- // TurboCAD SDK: function to add a circle to the active drawing
- void CMakeDwgDlg::OnAddCircle()
- {
- // Pointer to Graphics collection
- Graphics* pGraphics = m_view.GetGraphics();
- CString strStr;
- if (pGraphics == NULL)
- {
- strStr.LoadString(IDS_NEEDNEWDRAWINGFIRST);
- AfxMessageBox(strStr);
- return;
- }
-
- // Pointer to graphic object
- IGraphic* pIGraphic = NULL;
- IGraphic* pTGraphic = NULL;
- double xc = 10.0;
- double yc = 10.0;
- double zc = 0.0;
- double xp = 15.0;
- double yp = 10.0;
- double zp = 0.0;
-
- // Add graphic to drawing
- HRESULT hRes = pGraphics->AddCircleCenterAndPoint(xc, yc, zc, xp, yp, zp, &pIGraphic);
- if (SUCCEEDED(hRes))
- {
- // Change pen color of circle
- Properties* pProp = NULL;
- Property* pPenColor = NULL;
-
- #if 1
- // Code to find out where the local server bug is...
- IDispatch* pDisp = NULL;
- hRes = pIGraphic->QueryInterface(IID_IDispatch, (void**)&pDisp);
- if (SUCCEEDED(hRes))
- {
- LPOLESTR oszProperties = OLESTR("Properties");
- DISPID dispid;
- hRes = pDisp->GetIDsOfNames(
- IID_NULL,
- &oszProperties,
- 1,
- 0,
- &dispid);
- if (SUCCEEDED(hRes))
- {
- VARIANTARG args[1];
- VariantInit(&args[0]);
- DISPPARAMS params = { args, NULL, 0, 0 };
- hRes = pDisp->Invoke(dispid,
- IID_NULL,
- 0,
- DISPATCH_PROPERTYGET,
- ¶ms,
- &args[0],
- NULL,
- NULL);
-
- if (SUCCEEDED(hRes) && args[0].vt == VT_DISPATCH)
- {
- // JON: DISP_E_BADVARTYPE returned here!
- // CGrfPropertiesObject::InternalQueryInterface on the server side IS returning S_OK.
- // But somewhere the OLE marshaller doesn't like it...
- hRes = args[0].pdispVal->QueryInterface(IID_Properties, (void**)&pProp);
- }
- VariantClear(&args[0]);
- }
-
- pDisp->Release();
- }
- #else
- hRes = pIGraphic->get_Properties(&pProp);
- #endif
- if (SUCCEEDED(hRes))
- {
- // Change pen color
- COleVariant var("PenColor");
- hRes = pProp->get_Item(&var, &pPenColor);
- if (SUCCEEDED(hRes))
- {
- var = (long)0x0000FF;
- hRes = pPenColor->put_Value(0, &var);
-
- pPenColor->Release();
- }
- pProp->Release();
- }
- CString str("Circle");
- BSTR var = str.AllocSysString();
- hRes = pGraphics->AddText(str.AllocSysString(),10.0, 10.0, 0.0, .5,
- COleVariant(3.1415/2.0),
- COleVariant(DISP_E_PARAMNOTFOUND, VT_ERROR),
- COleVariant(DISP_E_PARAMNOTFOUND, VT_ERROR),
- COleVariant(DISP_E_PARAMNOTFOUND, VT_ERROR),
- &pTGraphic);
- // Finished with graphic, decrement the reference count
- if (SUCCEEDED(hRes))
- pTGraphic->Release();
- pIGraphic->Release();
- }
-
- // Finished with Graphics collection, decrement the reference count
- pGraphics->Release();
-
- // Zoom view to extents and invalidate window
- m_view.ZoomAndInvalidate();
- }
-
- // TurboCAD SDK: function to add a line to the active drawing
- void CMakeDwgDlg::OnAddLine()
- {
- // Pointer to Graphics collection
- Graphics* pGraphics = m_view.GetGraphics();
- CString strStr;
- if (pGraphics == NULL)
- {
- strStr.LoadString(IDS_NEEDNEWDRAWINGFIRST);
- AfxMessageBox(strStr);
- return;
- }
-
- // Pointer to graphic object
- IGraphic* pIGraphic = NULL;
- double x0 = 5.0;
- double y0 = 10.0;
- double z0 = 0.0;
- double x1 = 15.0;
- double y1 = 10.0;
- double z1 = 0.0;
-
- // Add graphic to drawing
- HRESULT hRes = pGraphics->AddLineSingle(x0, y0, z0, x1, y1, z1, &pIGraphic);
-
- if (SUCCEEDED(hRes))
- {
- // Finished with graphic, decrement reference count
- pIGraphic->Release();
- }
-
- // Finished with the Graphics collection, decrement reference count
- pGraphics->Release();
-
- // Zoom view to extents and invalidate window
- m_view.ZoomAndInvalidate();
- }
-
- // TurboCAD SDK: function to add a spline to the active drawing
- void CMakeDwgDlg::OnAddSpline()
- {
- const int NSPLPOINTS = 5;
- static double x[NSPLPOINTS] = { 1.0, 2.0, 5.0, 7.0, 9.0 };
- static double y[NSPLPOINTS] = { 4.0, 6.0, 4.0, 2.0, 5.0 };
- static double z[NSPLPOINTS] = { 0.0, 0.0, 0.0, 0.0, 0.0 };
- CString strStr;
- // Pointer to Graphics collection
- Graphics* pGraphics = m_view.GetGraphics();
- if (pGraphics == NULL)
- {
- strStr.LoadString(IDS_NEEDNEWDRAWINGFIRST);
- AfxMessageBox(strStr);
- return;
- }
-
- // Pointer to graphic object
- IGraphic* pIGraphic = NULL;
-
- // Add graphic to drawing with starting vertex x[0], y[0], z[0]
- HRESULT hRes = pGraphics->AddCurveSpline(x[0], y[0], z[0], &pIGraphic);
- if (SUCCEEDED(hRes))
- {
- Vertices* pVertices = NULL;
- hRes = pIGraphic->get_Vertices(&pVertices);
- if (SUCCEEDED(hRes))
- {
- // Make a "missing" optional parameter
- VARIANT var;
- var.vt = VT_ERROR;
- var.scode = DISP_E_PARAMNOTFOUND;
-
- // Add rest of points to spline curve
- VARIANT varX;
- varX.vt = VT_R8;
- VARIANT varY;
- varY.vt = VT_R8;
- VARIANT varZ;
- varZ.vt = VT_R8;
- int i;
- for (i = 1; i < NSPLPOINTS; ++i)
- {
- varX.dblVal = x[i];
- varY.dblVal = y[i];
- varZ.dblVal = z[i];
- IVertex* pIVertex = NULL;
- hRes = pVertices->Add(&varX, &varY, &varZ,
- &var, &var, &var, &var, &var, &var, &var, &var, &pIVertex);
- if (pIVertex != NULL)
- pIVertex->Release();
- }
- pVertices->Release();
-
- // Change pen color of spline
- Properties* pProp = NULL;
- Property* pPenColor = NULL;
-
- hRes = pIGraphic->get_Properties(&pProp);
- if (SUCCEEDED(hRes))
- {
- // Change pen color
- COleVariant var("PenColor");
- hRes = pProp->get_Item(&var, &pPenColor);
- if (SUCCEEDED(hRes))
- {
- var = (long)0x00FF00;
- hRes = pPenColor->put_Value(0, &var);
-
- pPenColor->Release();
- }
- pProp->Release();
- }
- }
-
- // Finished with graphic, decrement the reference count
- pIGraphic->Release();
- }
-
- // Finished with Graphics collection, decrement reference count
- pGraphics->Release();
-
- // Zoom view to extents and invalidate window
- m_view.ZoomAndInvalidate();
- }
-
- // TurboCAD SDK: function to add a bezier curve to the active drawing
- void CMakeDwgDlg::OnAddBezier()
- {
- const int NBEZPOINTS = 7;
- static double x[NBEZPOINTS] = { 1.0, 2.0, 5.0, 7.0, 9.0, 10.0, 11.0 };
- static double y[NBEZPOINTS] = { 4.0, 6.0, 4.0, 2.0, 5.0, 4.0, 2.0 };
- static double z[NBEZPOINTS] = { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 };
- CString strStr;
- // Pointer to Graphics collection
- Graphics* pGraphics = m_view.GetGraphics();
- if (pGraphics == NULL)
- {
- strStr.LoadString(IDS_NEEDNEWDRAWINGFIRST);
- AfxMessageBox(strStr);
- return;
- }
-
- // Pointer to graphic object
- IGraphic* pIGraphic = NULL;
-
- // Add graphic to drawing with starting vertex x[0], y[0], z[0]
- HRESULT hRes = pGraphics->AddCurveBezier(x[0], y[0], z[0], &pIGraphic);
- if (SUCCEEDED(hRes))
- {
- Vertices* pVertices = NULL;
- hRes = pIGraphic->get_Vertices(&pVertices);
- if (SUCCEEDED(hRes))
- {
- // Make a "missing" optional parameter
- VARIANT varMissing;
- varMissing.vt = VT_ERROR;
- varMissing.scode = DISP_E_PARAMNOTFOUND;
-
- // Add rest of points to spline curve
- VARIANT varX;
- varX.vt = VT_R8;
- VARIANT varY;
- varY.vt = VT_R8;
- VARIANT varZ;
- varZ.vt = VT_R8;
- int i;
- for (i = 1; i < NBEZPOINTS; ++i)
- {
- varX.dblVal = x[i];
- varY.dblVal = y[i];
- varZ.dblVal = z[i];
-
- // Make and set the "Calculated" parameter
- // On-curve points are not calculated.
- // Off-curve points are calculated.
- VARIANT varCalculated;
- varCalculated.vt = VT_BOOL;
- varCalculated.boolVal = ((i % 3) != 0) ? -1 : 0;
-
- IVertex* pIVertex = NULL;
- hRes = pVertices->Add(&varX, &varY, &varZ,
- &varMissing, &varMissing, &varMissing, &varMissing, &varMissing,
- &varCalculated, &varMissing, &varMissing, &pIVertex);
- if (pIVertex != NULL)
- pIVertex->Release();
- }
- pVertices->Release();
-
- // Change pen color of spline
- Properties* pProp = NULL;
- Property* pPenColor = NULL;
-
- hRes = pIGraphic->get_Properties(&pProp);
- if (SUCCEEDED(hRes))
- {
- // Change pen color
- COleVariant var("PenColor");
- hRes = pProp->get_Item(&var, &pPenColor);
- if (SUCCEEDED(hRes))
- {
- var = (long)0x00FF00;
- hRes = pPenColor->put_Value(0, &var);
-
- pPenColor->Release();
- }
- pProp->Release();
- }
- }
-
- // Finished with graphic, decrement the reference count
- pIGraphic->Release();
- }
- // Finished with Graphics collection, decrement reference count
- pGraphics->Release();
-
- // Zoom view to extents and invalidate window
- m_view.ZoomAndInvalidate();
- }
-
- HRESULT CMakeDwgDlg::SetupView(IDrawing* pIDrawing)
- {
- // Pointer to View collection
- Views* pViews = NULL;
-
- // Get the handle to the view collection
- HRESULT hRes = pIDrawing->get_Views(&pViews);
- if (SUCCEEDED(hRes))
- {
- // Pointer to view object
- View* pView = NULL;
-
- // Make a "missing" optional parameter
- VARIANT var;
- var.vt = VT_ERROR;
- var.scode = DISP_E_PARAMNOTFOUND;
-
- // Add the view to the collection
- hRes = pViews->Add(&var, &var, &pView);
-
- if (SUCCEEDED(hRes))
- {
- // Set up view to be the active view
- m_view.SetView(pView);
-
- // Finished with view, decrement reference count
- pView->Release();
- }
-
- // Finished with views, decrement reference count
- pViews->Release();
- }
- return hRes;
- }
-
-
- void CMakeDwgDlg::EnableButtons()
- {
- BOOL bEnable = (m_pIApplication != NULL);
- GetDlgItem(IDC_INPROC_SERVER)->EnableWindow(!bEnable);
- GetDlgItem(IDC_LOCAL_SERVER)->EnableWindow(!bEnable);
- GetDlgItem(IDC_NEWDRAWING)->EnableWindow(bEnable);
- GetDlgItem(IDC_OPENDRAWING)->EnableWindow(bEnable);
-
- if (bEnable)
- {
- bEnable = FALSE;
- Graphics* pGraphics = m_view.GetGraphics();
- if (pGraphics != NULL)
- {
- bEnable = TRUE;
- pGraphics->Release();
- }
- }
- GetDlgItem(IDC_ADDCIRCLE)->EnableWindow(bEnable);
- GetDlgItem(IDC_ADDLINE)->EnableWindow(bEnable);
- GetDlgItem(IDC_ADDSPLINE)->EnableWindow(bEnable);
- GetDlgItem(IDC_ADDBEZIER)->EnableWindow(bEnable);
- GetDlgItem(IDC_SAVEDRAWING)->EnableWindow(bEnable);
- }
-
- void CMakeDwgDlg::SyncToApplication()
- {
- if (m_pIApplication == NULL)
- return;
-
- // Pointer to Drawings collection
- Drawings* pDrawings = NULL;
-
- // Get the handle to the drawings collection
- HRESULT hRes = m_pIApplication->get_Drawings(&pDrawings);
- if (SUCCEEDED(hRes))
- {
- COleVariant varIndex;
- varIndex.vt = VT_I4;
- for (varIndex.lVal = 0L; ; ++varIndex.lVal)
- {
- IDrawing* pIDrawing = NULL;
- hRes = pDrawings->get_Item(&varIndex, &pIDrawing);
- if (FAILED(hRes))
- break;
- BSTR bstrName = NULL;
- hRes = pIDrawing->get_Name(&bstrName);
- if (SUCCEEDED(hRes))
- {
- ASSERT(bstrName != NULL);
- CString strName = bstrName;
- ::SysFreeString(bstrName);
- CListBox* pList = (CListBox*)GetDlgItem(IDC_LISTDRAWINGS);
- int iString = pList->AddString(strName);
- if (varIndex.lVal == 0)
- {
- pList->SetCurSel(iString);
- SetupView(pIDrawing);
- }
- }
-
- // Finished with drawing object, decrement reference count
- pIDrawing->Release();
- }
- pDrawings->Release();
- }
-
- }
-
- void CMakeDwgDlg::OnInprocServer()
- {
- CString strStr;
- // TurboCAD SDK: Connect to the server
- HRESULT hRes = CoCreateInstance(
- CLSID_XApplication, //Class identifier (CLSID) of the object
- NULL, //Object is or isn't part of an aggregate
- CLSCTX_INPROC_SERVER, //Context for running executable code
- IID_IApplication, //Interface identifier
- (void**)&m_pIApplication //Points to requested interface pointer
- );
-
- if (FAILED(hRes))
- {
- strStr.LoadString(IDS_COULDNOT_CREATE_INPROC_SERVER);
- AfxMessageBox(strStr);
- }
-
- EnableButtons();
- }
-
- extern "C" const IID IID_IPickRectSink = {0x6A481202,0xE531,0x11CF,{0xA1,0x15,0x00,0xA0,0x24,0x15,0x8D,0xAF}};
-
- void CMakeDwgDlg::OnLocalServer()
- {
- CString strStr;
- // TurboCAD SDK: Connect to the server
- HRESULT hRes = CoCreateInstance(
- CLSID_Application, //Class identifier (CLSID) of the object
- NULL, //Object is or isn't part of an aggregate
- CLSCTX_LOCAL_SERVER, //Context for running executable code
- IID_IApplication, //Interface identifier
- (void**)&m_pIApplication //Points to requested interface pointer
- );
-
- if (FAILED(hRes))
- {
- strStr.LoadString(IDS_COULDNOT_CREATE_LOCAL_SERVER);
- AfxMessageBox(strStr);
- }
-
- SyncToApplication();
- EnableButtons();
- }
-
- void CMakeDwgDlg::OnGetActive()
- {
-
- if (m_pIApplication != NULL)
- return;
-
- CString strStr;
- // Try to connect to running TurboCAD
- IUnknown* pUnk = NULL;
- HRESULT hRes = ::GetActiveObject(CLSID_Application, NULL, &pUnk);
- if (FAILED(hRes))
- {
- strStr.LoadString(IDS_TCAD_ISNOT_ACTIVE);
- AfxMessageBox(strStr);
- return;
- }
- hRes = pUnk->QueryInterface(IID_IApplication, (void**)&m_pIApplication);
- pUnk->Release();
- if (FAILED(hRes))
- {
- strStr.LoadString(IDS_OBJECT_ISNOT_TCADAPP);
- AfxMessageBox(strStr);
- }
-
- SyncToApplication();
- EnableButtons();
- }
-
- // TurboCAD SDK: function to an active drawing to the application
- void CMakeDwgDlg::OnNewDrawing()
- {
- // Pointer to Drawings collection
- Drawings* pDrawings = NULL;
-
- // Get the handle to the drawings collection
- HRESULT hRes = m_pIApplication->get_Drawings(&pDrawings);
- if (FAILED(hRes))
- {
- return;
- }
-
- // Pointer to drawing object
- IDrawing* pIDrawing = NULL;
-
- // Make a "missing" optional parameter
- VARIANT var;
- var.vt = VT_ERROR;
- var.scode = DISP_E_PARAMNOTFOUND;
-
- // Add the new drawing to the drawings collection
- hRes = pDrawings->Add(&var, &pIDrawing);
- if (SUCCEEDED(hRes))
- {
- long lCount = 0;
- hRes = pDrawings->get_Count(&lCount);
-
- char szName[32];
- wsprintf(szName, "Drawing %ld", lCount);
- CListBox* pList = (CListBox*)GetDlgItem(IDC_LISTDRAWINGS);
- pList->SetCurSel(pList->AddString(szName));
-
- hRes = SetupView(pIDrawing);
-
- // Finished with drawing object, decrement reference count
- pIDrawing->Release();
- }
-
- // Finished with drawings collection, decrement reference count
- pDrawings->Release();
-
- EnableButtons();
- }
-
-
- static char BASED_CODE szFilter[] = "TurboCAD Drawing Files (*.tcw)|*.tcw|All Files (*.*)|*.*||";
-
- void CMakeDwgDlg::OnOpenDrawing()
- {
- CFileDialog dlg(TRUE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this);
- if (dlg.DoModal() != IDOK)
- return;
-
- // Pointer to Drawings collection
- Drawings* pDrawings = NULL;
-
- // Get the handle to the drawings collection
- HRESULT hRes = m_pIApplication->get_Drawings(&pDrawings);
- if (FAILED(hRes))
- {
- return;
- }
-
- // Pointer to drawing object
- IDrawing* pIDrawing = NULL;
-
- // Make a "missing" optional parameter
- VARIANT var;
- var.vt = VT_ERROR;
- var.scode = DISP_E_PARAMNOTFOUND;
-
- // Get the file name into a BSTR
- CString strPath = dlg.GetPathName();
- BSTR bstrPath = strPath.AllocSysString();
-
- // Add the drawing to the drawings collection
- hRes = pDrawings->Open(bstrPath, &var, &var, &pIDrawing);
-
- // Free the system memory for the BSTR
- ::SysFreeString(bstrPath);
-
- if (SUCCEEDED(hRes))
- {
- CListBox* pList = (CListBox*)GetDlgItem(IDC_LISTDRAWINGS);
- pList->SetCurSel(pList->AddString(strPath));
-
- hRes = SetupView(pIDrawing);
-
- // Finished with drawing object, decrement reference count
- pIDrawing->Release();
- }
- else
- {
- // File was not opened. Maybe the filter gave us a reason.
- CString strDesc("Unknown");
-
- // Try to get thread-wide error object
- IErrorInfo* pErrorInfo = NULL;
- if (SUCCEEDED(::GetErrorInfo(0, &pErrorInfo)))
- {
- // Try to get description string
- BSTR bstrDesc = NULL;
- if (SUCCEEDED(pErrorInfo->GetDescription(&bstrDesc)))
- {
- strDesc = bstrDesc;
- ::SysFreeString(bstrDesc);
- }
- pErrorInfo->Release();
- }
-
- // Display failure message
- CString msg = "Could not open '" + strPath + "': " + strDesc;
- MessageBox(msg);
- }
-
- // Finished with drawings collection, decrement reference count
- pDrawings->Release();
-
- EnableButtons();
- }
-
- void CMakeDwgDlg::OnSaveDrawing()
- {
- // Pointer to Drawing object
- IDrawing* pIDrawing = m_view.GetDrawing();
- CString strStr;
- if (pIDrawing == NULL)
- {
- strStr.LoadString(IDS_NEEDNEWDRAWINGFIRST);
- AfxMessageBox(strStr);
- return;
- }
-
- CFileDialog dlg(FALSE, NULL, NULL, OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, szFilter, this);
- if (dlg.DoModal() == IDOK)
- {
- // Make a "missing" optional parameter
- VARIANT var;
- var.vt = VT_ERROR;
- var.scode = DISP_E_PARAMNOTFOUND;
-
- // Get the file name into a BSTR
- CString strPath = dlg.GetPathName();
- BSTR bstrPath = strPath.AllocSysString();
-
- HRESULT hRes = pIDrawing->SaveAs(bstrPath, &var);
-
- // Free the system memory for the BSTR
- ::SysFreeString(bstrPath);
- }
-
- // Done with drawing
- pIDrawing->Release();
- }
-
- void CMakeDwgDlg::OnSelchangeDrawings()
- {
- if (m_pIApplication == NULL)
- return;
-
- CListBox* pList = (CListBox*)GetDlgItem(IDC_LISTDRAWINGS);
- long l = pList->GetCurSel();
- if (l < 0)
- return;
-
- Drawings* pDrawings = NULL;
- HRESULT hRes = m_pIApplication->get_Drawings(&pDrawings);
- if (FAILED(hRes))
- return;
-
- COleVariant var(l);
- IDrawing* pIDrawing = NULL;
- hRes = pDrawings->get_Item(&var, &pIDrawing);
- if (SUCCEEDED(hRes))
- {
- hRes = pIDrawing->Activate();
- hRes = SetupView(pIDrawing);
-
- // Finished with drawing object, decrement reference count
- pIDrawing->Release();
- }
-
- EnableButtons();
- }
-
-
- void CMakeDwgDlg::OnDestroy()
- {
- CDialog::OnDestroy();
-
- m_view.SetView(NULL);
-
- // Finished with application, decrement the reference count
- if (m_pIApplication != NULL)
- {
- m_pIApplication->Release();
- m_pIApplication = NULL;
- }
- }
-
- void CMakeDwgDlg::OnCurveSmooth()
- {
- // Pointer to Graphics collection
- Graphics* pGraphics = m_view.GetGraphics();
- CString strStr;
- if (pGraphics == NULL)
- {
- strStr.LoadString(IDS_NEEDNEWDRAWINGFIRST);
- AfxMessageBox(strStr);
- return;
- }
-
- // Pointer to graphic object
- IGraphic* pIGraphic;
- COleVariant varIndex(0L);
- HRESULT hRes = pGraphics->get_Item(&varIndex, &pIGraphic);
- if (SUCCEEDED(hRes))
- {
- Properties* prop = NULL;
- Property* fprop = NULL;
- if (SUCCEEDED(pIGraphic->get_Properties(&prop)))
- {
- COleVariant vsmooth("$CurveSmooth");
- hRes = prop->get_Item(&vsmooth, &fprop);
- if (SUCCEEDED(hRes))
- {
- COleVariant varValue;
- hRes = fprop->get_Value(0, &varValue);
- if (SUCCEEDED(hRes))
- {
- ASSERT(varValue.vt == VT_I2);
- if (varValue.iVal)
- varValue.iVal = 0;
- else
- varValue.iVal = 1;
- fprop->put_Value(0, &varValue);
- m_view.Invalidate();
- }
- fprop->Release();
- }
- prop->Release();
- }
- pIGraphic->Release();
- }
- pGraphics->Release();
- }
-